import main.HDFSUtil
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.FileSystem
import org.apache.hadoop.fs.Path
import org.junit.Test

class MainTest {
  @Test
  fun test() {
    System.setProperty("HADOOP_USER_NAME", "root")
    val content = "xxx"
    HDFSUtil.createFile("/test/input.txt", content)
    HDFSUtil.readFile("/test/input.txt")
    HDFSUtil.deleteFile("/test/input.txt")
    HDFSUtil.uploadFile("D:/Users/xx/1.txt", "/test/input/file/input.txt")
    HDFSUtil.readFile("/test/input/file/input.txt")
    HDFSUtil.createFile("/test/input/hello.txt", "iuyfrgti8eqwgfiu")
    HDFSUtil.showFile("/", true)
    HDFSUtil.showLocation("/test/input/hello.txt")
    HDFSUtil.showDataNodeName()
    HDFSUtil.close()
  }

  @Test
  fun test1() {
    val conf = Configuration()
    conf.set("fs.defaultFS", "hdfs://192.168.244.143:9000")
    System.setProperty("HADOOP_USER_NAME", "root")
    val fs = FileSystem.get(conf)
    val srcPath = "D:/Users/xx/1.txt"
    val src = Path(srcPath)
    val dst = Path("/test/input")
    fs.copyFromLocalFile(src, dst)
    fs.close()
  }
}